package cn.south.campus.admin.sys.model.vo;

import cn.south.campus.admin.sys.model.entity.SysUser;
import cn.south.campus.common.model.vo.BaseVO;
import cn.south.campus.common.utils.DateUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * @author chow
 * @since 2024/10/31
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class SysUserVo extends BaseVO {

    /**
     * 昵称
     */
    private String username;

    /**
     * 头像
     */
    private String avatar;

    /**
     * 手机号
     */
    private String mobile;

    /**
     * 邮箱
     */
    private String email;

    /**
     * 角色id
     */
    private Long roleId;
    /**
     * 角色名称
     */
    private String roleName;

    /**
     * 部门id
     */
    private Long deptId;
    /**
     * 部门名称
     */
    private String deptName;
    /**
     * 1 有效 2 无效
     */
    private Integer locked;

    public static SysUserVo convert(SysUser sysUser) {
        if (sysUser == null) {
            return null;
        }
        SysUserVo sysUserVo = new SysUserVo();
        sysUserVo.setId(sysUser.getId());
        sysUserVo.setUsername(sysUser.getUsername());
        sysUserVo.setAvatar(sysUser.getAvatar());
        sysUserVo.setMobile(sysUser.getMobile());
        sysUserVo.setEmail(sysUser.getEmail());
        sysUserVo.setRoleId(sysUser.getRoleId());
        sysUserVo.setRoleName(sysUser.getRoleName());
        sysUserVo.setDeptId(sysUser.getDeptId());
        sysUserVo.setDeptName(sysUser.getDeptName());
        sysUserVo.setCreateTime(DateUtil.format(sysUser.getCreateTime()));
        sysUserVo.setUpdateTime(DateUtil.format(sysUser.getUpdateTime()));
        sysUserVo.setLocked(sysUser.getLocked());
        return sysUserVo;
    }

    public static SysUser convert(SysUserVo vo) {
        if (vo == null)
            return null;
        SysUser entity = new SysUser();
        entity.setId(vo.getId());
        entity.setUsername(vo.getUsername());
        entity.setAvatar(vo.getAvatar());
        entity.setMobile(vo.getMobile());
        entity.setEmail(vo.getEmail());
        entity.setRoleId(vo.getRoleId());
        entity.setRoleName(vo.getRoleName());
        entity.setDeptId(vo.getDeptId());
        entity.setDeptName(vo.getDeptName());
        entity.setCreateTime(DateUtil.parseString(vo.getCreateTime()));
        entity.setUpdateTime(DateUtil.parseString(vo.getUpdateTime()));
        entity.setLocked(vo.getLocked());
        return entity;
    }
}
